// const checkName = (rule, value, callback) => {
//     if (value === "") {
//         callback(new Error("Please enter your full name"));
//     } else {
//         // 英文校验规则
//         // -------------！！！注意：转义特殊字符'-'
//         const regEn = /[`~!@#$%^&*()_\-+=<>?:"{},.\\/;'[\]]/im;
//         // 中文校验规则
//         const regCn = /[·！#￥（——）：；“”‘、，|《。》？、【】[\]]/im;
//         if (regEn.test(value) || regCn.test(value)) {
//             callback(
//                 new Error(
//                     "Recipient name should be pure letters (spaces allowed)"
//                 )
//             );
//         } else {
//             callback();
//         }
//     }
// };
// const checkPhone = (rule, value, callback) => {
//     if (value === "") {
//         callback(new Error("Please enter a valid phone number"));
//     } else {
//         const reg = /[A-z]+/g;
//         if (reg.test(value)) {
//             callback(new Error("Phone number cannot enter letters"));
//         } else {
//             callback();
//         }
//     }
// };
// const checkAddress = (rule, value, callback) => {
//     if (value === "") {
//         callback(new Error("Please enter your address"));
//     } else {
//         let length = (value || "").length;
//         let reg = /[a-zA-z]+/;
//         if (!reg.test(value) || length <= 7) {
//             callback(
//                 new Error(
//                     "Address must be at least 8 characters long and cannot be only as numbers"
//                 )
//             );
//         } else {
//             callback();
//         }
//     }
// };
// const checkState = (rule, value, callback) => {
//     if (value === "") {
//         callback();
//         // callback(new Error("Please enter the State/Region"));
//     } else {
//         let reg = /^[0-9a-zA-Z\s]*/;
//         if (value.replace(reg, "") != "") {
//             callback(new Error("Only letters, numbers, spaces are allowed"));
//         } else {
//             callback();
//         }
//         callback();
//     }
// };

export const rules = {
    first_name: [
        {
            required: true,
            message: "Please enter your full name",
            trigger: "blur",
        },
        {
            pattern:
                /^[^`~!@#$%^&*()_\-+=<>?:"{},.\/;'\[\]！#￥（——）：；“”‘、，|《。》？、【】]+$/,
            message: "Recipient name should be pure letters (spaces allowed)",
            trigger: ["change", "blur"],
        },
    ],
    name: [
        {
            required: true,
            message: "Please enter your full name",
            trigger: "blur",
        },
    ],
    phone: [
        {
            required: true,
            message: "Please enter your phone number",
            trigger: "blur",
        },
        {
            pattern: /^[\d-\s]+$/,
            message: "Phone number cannot enter letters",
            trigger: ["change", "blur"],
        },
    ],
    country_code: [
        {
            required: true,
            message: "Please select the Country",
            trigger: "change",
        },
    ],
    // country: [
    //     {
    //         required: true,
    //         message: "Please select the Country",
    //         trigger: "change",
    //     },
    // ],
    city: [
        {
            required: true,
            message: "Please fill your city",
            trigger: "blur",
        },
    ],
    post_code: [
        {
            required: true,
            message: "Please enter the postal/ZIP code",
            trigger: "blur",
        },
    ],
    email: [
        {
            required: false,
            message: "Please input your Email",
            trigger: "blur",
        },
        {
            pattern: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
            message: "Email format error",
            trigger: ["change", "blur"],
        },
    ],
    state: [
        {
            required: false,
            message: "Please enter the State/Region",
            trigger: "blur",
        },
        // {
        //     pattern: /^[\w\d\s\(\)]+$/,
        //     message: "Only letters, numbers, spaces are allowed",
        //     trigger: ["change", "blur"],
        // },
    ],
    street: [
        {
            required: true,
            message: "Please enter your address",
            trigger: "blur",
        },
        {
            min: 8,
            message: "Address must be at least 8 characters long",
            trigger: ["change", "blur"],
        },
        {
            pattern: /[\D]+/,
            message: "Address cannot be only as numbers",
            trigger: ["change", "blur"],
        },
    ],
    district: [
        {
            required: false,
            message: "Please enter your address",
            trigger: "blur",
        },
    ],
};
export const deepCopy = (source, cache) => {
    if (!cache) {
        cache = new Map();
    }
    if (source instanceof Object) {
        // 不考虑跨 iframe
        if (cache.get(source)) {
            return cache.get(source);
        }
        let result;
        if (source instanceof Function) {
            if (source.prototype) {
                // 有 prototype 就是普通函数
                result = function () {
                    return source.apply(this, arguments);
                };
            } else {
                result = (...args) => {
                    return source.call(undefined, ...args);
                };
            }
        } else if (source instanceof Array) {
            result = [];
        } else if (source instanceof Date) {
            result = new Date(source - 0);
        } else if (source instanceof RegExp) {
            result = new RegExp(source.source, source.flags);
        } else {
            result = {};
        }
        cache.set(source, result);
        for (let key in source) {
            if (source.hasOwnProperty(key)) {
                result[key] = deepCopy(source[key], cache);
            }
        }
        return result;
    } else {
        return source;
    }
};

export const getRules = () => {
    return deepCopy(rules);
};

export default getRules;
